package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.service.MenuService;
import com.itheima.service.PermissionService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissController {

    @Reference
    private PermissionService permissionService;

    @Reference
    private MenuService menuService;

    //查询所有权限信息
    @RequestMapping("/findAll")
    public Result findAllPermission(){
        try {
            List<Permission> list = permissionService.findAll();
            return new Result(true, "查询所有权限信息成功", list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "查询所有权限信息失败");
        }
    }

    //查询角色与权限的关联id
    @RequestMapping("/findPermissionIdsByRoleId")
    public Result findPermissionIdsByRoleId(Integer id){
        try {
            List<Integer> list = permissionService.findPermissionIdsByRoleId(id);
            return new Result(true, "查询权限角色关联成功", list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "查询权限角色关联id失败");
        }
    }
}
